# _*_ coding：UTF-8 _*_
# @Time：2021/9/416:27
# @Author：JYZ
# @Project：oneWork

import urllib.request

# 请求地址
url = "http://www.baidu.com"

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'}

request = urllib.request.Request(url=url, headers=headers)

# 获取handle 对象
handle = urllib.request.HTTPHandler()

# 获取opener 对象
opener = urllib.request.build_opener()

# 调用open方法
response = opener.open(request)

content = response.read().decode("utf-8")

print(content)

